import datetime

class DbModel:
    def load(self, obj):
        if not isinstance(obj, dict):
            raise TypeError("obj must be a dict")
        for k, v in obj.items():
            if hasattr(self, k):
                setattr(self, k, v)
        return self

class TaskStatus:
    New = 0
    Running = 1
    Stop = 2
    Finish = 3
    Error = 4
    
class DbTask(DbModel):
    def __init__(self):
        self.id : str = 0
        self.user_id: int = 0
        self.name: str = ''
        self.proxy: str = ''
        self.platform_id: int = 0
        self.threads: int = 1
        self.car_numbers: str = ''
        self.status: TaskStatus = 0
        self.error: str = ''
        self.erased: int = 0
        self.gmt_create: datetime.datetime = None
        self.gmt_modified: datetime.datetime = None
        
class DbTaskRecord(DbModel):
    def __init__(self):
        self.id : str = 0
        self.user_id: int = 0
        self.task_id: int = 0
        self.content: int = ''
        self.erased: int = 0
        self.gmt_create: datetime.datetime = None
        self.gmt_modified: datetime.datetime = None
        
class DbParkRecord(DbModel):
    def __init__(self):
        self.id : int = 0
        self.park_name: str = ''
        self.user_id: int = 0
        self.car_number: str = ''
        self.task_id: int = 0
        self.platform_id: int = 0
        self.entry_time: datetime.datetime = None
        self.parking_often: str = ''
        self.parking_fees: str = ''
        self.erased: int = 0
        self.gmt_create: datetime.datetime = None
        self.gmt_modified: datetime.datetime = None
        
class DbParkToken(DbModel):
    def __init__(self):
        self.id : str = 0
        self.user: str = ''
        self.platform_id: int = 0
        self.data: str = ''
        self.erased: int = 0
        self.gmt_create: datetime.datetime = None
        self.gmt_modified: datetime.datetime = None
        